package com.CoreryBlack.service.Impl;

import com.CoreryBlack.Mapper.DeptMapper;
import com.CoreryBlack.po.Dept;
import com.CoreryBlack.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @Description DeptServiceImpl
 * @Author CoreryBlack
 * @Date 2024-09-20
 */
@Component
public class DeptServiceImpl implements DeptService {


    public DeptServiceImpl(){
        System.out.println("正在创建Service...");
    }

    @Autowired
    private DeptMapper deptMapper;

    public List<Dept> queryDept() {
        List<Dept> deptList = deptMapper.findAll();
        return deptList;
    }

    public void deleteById(Integer id) {
        deptMapper.deleteById(id);
    }


    public void saveDept(Dept dept) {
        //1、补充基础属性
        dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());

        //2、调用Mapper操作数据库
        deptMapper.insert(dept);
    }

    public Dept getById(Integer id) {
        return deptMapper.getById(id);
    }

    public void update(Dept dept) {
        dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.updateById(dept);
    }
}